package com.xunfang.controller;

import com.xunfang.bean.House;
import com.xunfang.bean.dto.HouseDTO;
import com.xunfang.bean.vo.PageVo;
import com.xunfang.common.Result;
import com.xunfang.service.IHouseService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2023 -11-08
 * @desc
 */
@Api
@RestController
@RequestMapping("house")
public class HouseController {

    @Autowired
    private IHouseService houseService;

    @GetMapping("/list/{currentPage}/{pageSize}")
    public Result findHouse(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        PageVo pageVo = houseService.findHouses(currentPage, pageSize);
        return Result.ok(pageVo);
    }

    @PostMapping
    public Result addHouse(@RequestBody HouseDTO houseDTO){
        boolean flag = houseService.saveUpdateHouse(houseDTO);
        return Result.ok();
    }

    @DeleteMapping("{id}")
    public Result deleteHouseById(@PathVariable Integer id){
        houseService.deleteHouseById(id);
        return  Result.ok();
    }

}
